<?php
include $_SERVER["DOCUMENT_ROOT"]."/inc/core/env.inc.php";

$_PAGE = new Page ($_GET["label"]);

//TODO: *********************************************************************
//TODO: load for each extension associated with the page: path, class and js
//TODO: *********************************************************************


$_PAGE->insertBody();

//loading page blocks
foreach ($_PAGE->get("blocks") as $i => $bId) {
	$block = new Block ($bId);
	$_PAGE->insertBlock($block);
}

//setting head
$_PAGE->insertHead();

//load administrator
if ($_SITE["admin"]["activate"]) {
	$_PAGE->insertAdmin();
}

//load js
$_PAGE->insertJs();

//debug
if ($_SITE["debug"]["activate"]) {
	$debug = "";
	$debug .= "Page id: ".$_PAGE->pId."<br />";
	$debug .= "Page pathTree: ".$_PAGE->get("path")."<br />";
	$debug .= "URI: ".$_SERVER["REQUEST_URI"]."<br />";
	$debug .= "PATH_STR: ".$_GET["path_str"]."<br />";
	$debug .= "LABEL: ".$_GET["label"]."<br />";
	$debug .= "Session: ".session_name()."<br /><br />";
	
	$debug .= print_r($_SESSION, true);
	
	foreach ($_ENV["debug"] as $row) {
		$debug .= $row; 
	}
	
	$_ENV["debug"] = array();
	
	$debug .= "------------------------------------------------------<br />";
	$debug .= '$_ENV <br />';
	$debug .= nl2br(str_replace(" ", "&nbsp;", print_r($_ENV, true)));
	$debug = str_replace("<!--", "< !--", $debug);
	
	$_PAGE->insertDebug($debug);
} else {
	$_PAGE->removeDivDebug();	
}

$_PAGE->clearTagBlocks();
$env["html"] = $_PAGE->html();
$env["html"] = $_TRANSLATE->traslate($env["html"], $_SESSION["LANGUAGE"]);

echo $env["html"];
?>